﻿app.controller('ProvideOrderController',
    [
    '$rootScope',
    '$scope',
    '$localStorage',
    '$state',
    '$stateParams',
    '$modal',
    'ManagerPackFactory', 'BitcoinFactory', '$filter', 'CN_TructiepFactory', 'commonFactory',
function ($rootScope, $scope, $localStorage, $state,$stateParams, $modal, ManagerPackFactory, BitcoinFactory, $filter, CN_TructiepFactory)
    {
        $scope.title = "PH Detail",
        $scope.messeger = "",
        $scope.orderId = $stateParams.orderId,
        $scope.popup = function (windowClass, StyleModal, Controller, size, param) {
            $modal.open({
                windowClass: windowClass,
                templateUrl: StyleModal,
                controller: Controller,
                size: size,
                resolve: {
                    messeger: function () {
                        return $scope.messeger;
                    },
                    title: function () {
                        return $scope.title;
                    },
                    param: function () {
                        return param;
                    }
                }
            })
        },
        $scope.ProvideOrderList = [],
        LoadProvideOrder($scope.orderId);
        function LoadProvideOrder(orderId) {
            commonFactory.loadProvideOrder(orderId).then(
                 function successCallback(resp) {
                     if (resp.data.Status) {
                         $scope.showProvideOrder = true;
                         $scope.ProvideOrderList = resp.data.Result;
                     } else {
                         $scope.message = resp.data.Msg;
                     }
                 })
        };
        $scope.doPay = function (item) {
            DoPay(item);
        };
        function DoPay(item)
        {
            var btc = parseFloat(item.Amount).toFixed(8);
            $state.go("app.payorder", { orderId: item.Id_Order, amount: btc, userRecieve: item.UserIdGet });
        }

        $scope.doSent = function (item) {
            sent(item);
        };

        function sent(item) {
            commonFactory.approveProvideOrder2(item.Id, item.RoomCode).then(function (rsp) {
                if (rsp.data.Status) {
                    $state.go('app.gethelp')
                } else {
                    $scope.messeger = rsp.data.Msg,
                    $scope.title = 'Warning',
                    $scope.popup('modal-message modal-warning', "WarningModal");
                }
            }, function (error) {
                $scope.status = 'Unable to load profile data: ' + error.message;
            });
        }
    }
]);
app.controller('BankDetailModalInstanceCtrl', function ($scope, $modalInstance, $localStorage, $state, $stateParams, $timeout, messeger, title, param, commonFactory) {
    $scope.messeger = messeger,
    $scope.title = "Bank Detail ",
    $scope.AlertType = "warning";
    $scope.processing = false,
    $scope.UserInfor = {},
    getUserById(param.UserIdGet);
    function getUserById(id) {
        commonFactory.getUserById(id).then(function (rsp)
        {
            $scope.UserInfor = rsp.data;              

        });
    };
    $scope.cancel = function () {
        $modalInstance.dismiss('cancel');
    };
    $scope.ok = function () {
        $modalInstance.close();
    };
    $scope.doSent = function () {
        sent(param);
    };
    //sent(param);
    function sent(param) {
        console.log(param.OrderId);
        commonFactory.approveProvideOrder2(param.Id, param.RoomCode).then(function (rsp) {
            if (rsp.data.Status) {
                $state.go('app.provideorder', { orderId: param.OrderId })
                $modalInstance.dismiss('cancel');
            } else {
                $scope.messeger = rsp.data.Msg,
                $scope.title = 'Warning',
                $scope.popup('modal-message modal-warning', "WarningModal");
            }
        }, function (error) {
            $scope.status = 'Unable to load profile data: ' + error.message;
        });
    }
});